<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<%
    String path = request.getContextPath();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta name="format-detection" content="telephone=no,email=no,adress=no" />
<META HTTP-EQUIV="luxiaoqing" CONTENT="no-cache">

<link rel="stylesheet"  type="text/css"  href="css/login.css" ><!-- 通用CSS -->
<link rel="stylesheet"  type="text/css"  href="css/business.css" /><!-- 商家CSS -->
<link rel="stylesheet"  type="text/css"  href="css/all.css" >

<script src="js/jquery-1.11.3.js" type="text/javascript"></script>
<script src="js/common.js"></script>

<title>重置密码</title>
</head>

	<body>
		<!--头部-->
		<div class="business_top">
			<div class="business_top-middle">
				<div class="business_top-logo">
					<a href="" title='商家首页'>
						<img src="images/logo02.png" />

					</a>
				</div>

				<div class="clear"></div>
			</div>

			<div class="clear"></div>
		</div>
		<!--头部end-->

		<div class="clear4"></div>

		<!--中间-->
		<div class="business_register-center">
			<div class="business_register-center-middle">
				<div class="clear1"></div>

				<div class="business_register-center-middle-title">
					<span>
	            		重置密码
            		</span>
            		<span class="fanhui">
		            	<a href="<%=path %>/toMerchantLogin.do">想起密码，立即登陆</a>
		            </span>
				</div>

				<div class="clear3"></div>
					<div class="business_register-center-middle-from">
						<div class="business_register-center-middle-form-number">
							<div class="business_login-center-middle-form-number-input no3">
								<input type="text" id="userName" name="phone" placeholder="手机号" title="请输入有效的手机" data-toggle="tooltip" />
							</div>
						</div>

						<div class="clear1"></div>

						<div class="business_register-center-middle-form-verification">
							<div class="business_register-center-middle-form-verification-text no3">
								<input type="text" id="phone_code" name='phone_code' placeholder="请输入短信验证码" required />
							</div>

							<div class="business_register-center-middle-form-verification-button">
								<input type="button" id="btn" value="获取验证码" />
							</div>
						</div>

						<div class="clear3"></div>

						<div class="business_register-center-middle-form-password">
							<div class="business_login-center-middle-form-password-input no3">
								<input type="password" id="password" name="password" placeholder="密码" title="请输入6-16位密码，字母区分大小写" data-toggle="tooltip" />
							</div>
						</div>

						<div class="clear3"></div>
						<div class="business_register-center-middle-form-sub">
							<input type="button" value="重置" onclick="updatePws();"/>
						</div>

						<div class="clear3"></div>
					</div>
			</div>
			<div class="clear2"></div>
		</div>
		<!--中间end-->

		<div class="clear2"></div>

		<!--底部-->
		<div class="business_foot">
			<jsp:include page="../lbi/merFooter.jsp"></jsp:include>
		</div>
		<!--底部end-->

		<div class="clear8"></div>

		<script type="text/javascript" src="js/jquery.validate.min.js"></script>
		<script type="text/javascript">
		var _serviceURL='/69mark';//必须设置

	    $('#btn').click(function(){
	        
	        var btn = $(this);
	        btn.attr("disabled", "disabled").addClass("dis");
	        var time = 60000;
	        var time2 = setInterval(function() {
	            time -= 1000;
	            if ((time / 1000) == 0) {
	                btn.val("重新发送");
	                window.clearInterval(time2);
	                btn.removeAttr("disabled").removeClass("dis");
	            }
	            else {
	                btn.val("重新发送(" + time / 1000 + ")");
	            }

	        }, 1000);
	        
	        var url = _serviceURL+"/toSmsSend.do";
	        var regPhone = /^1([3578]\d|4[57])\d{8}$/;
	        var userName = $("#userName").val();
	        if (userName !=null &&  regPhone.test( userName )) {
	            $.post(url,{'userName':userName},function(data){
	                if (data == "1") {
	                }else if (data == "2") {
	                    alert('该账号已被注册');
	                    btn.val("重新发送");
	                    window.clearInterval(time2);
	                    btn.removeAttr("disabled").removeClass("dis");
	                }else{
	                    alert('短信发送失败。');
	                    btn.val("重新发送");
	                    window.clearInterval(time2);
	                    btn.removeAttr("disabled").removeClass("dis");
	                }
	            })
	        }else {
	            alert("填写正确手机号");
	            btn.val("重新发送");
	            window.clearInterval(time2);
	            btn.removeAttr("disabled").removeClass("dis");
	        }
	    })
	    
	    function updatePws(){
	        var password = $("#password").val();
	        var userName = $("#userName").val();
	        var phone_code = $("#phone_code").val();
	        
	        $.ajax({
	            type : "POST",
	            url : _serviceURL+"/toUpdatePws.do",
	            cache : false,
	            data : "userName="+userName+"&password="+password+"&phone_code="+phone_code,
	            dataType : 'json',
	            success : function(data) {
	                if (data == 1) {
	                    alert("修改成功");
	                    
	                    window.location.href = _serviceURL+"/toMerchantLogin.do";
	                    
	                }else if (data == 0) {
	                    alert("旧密码输入错误");
	                }
	            }
	        })
	    }
		</script>
	</body>

</html>